<?php

/**
 * This is the model class for table "xyh_activity_link_vote_q".
 *
 * The followings are the available columns in table 'xyh_activity_link_vote_q':
 * @property string $id
 * @property string $activity_id
 * @property string $q_content
 * @property string $type_id
 * @property string $sort
 */
class ActivityLinkVoteQ extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return ActivityLinkVoteQ the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xyh_activity_link_vote_q';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('activity_id, sort', 'length', 'max'=>10),
			array('q_content', 'length', 'max'=>255),
			array('type_id', 'length', 'max'=>2),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, activity_id, q_content, type_id, sort', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    
                      'ActivityLinkVoteA' => array(self::HAS_MANY, 'ActivityLinkVoteA', 'vote_q_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'activity_id' => 'Activity',
			'q_content' => 'Q Content',
			'type_id' => 'Type',
			'sort' => 'Sort',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search($activity_id)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

                if($activity_id)
                    $criteria->addCondition("activity_id=$activity_id");
                
		$criteria->compare('id',$this->id,true);
		$criteria->compare('activity_id',$this->activity_id,true);
		$criteria->compare('q_content',$this->q_content,true);
		$criteria->compare('type_id',$this->type_id,true);
		$criteria->compare('sort',$this->sort,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        
        
        public function get_answer($id){
            
//            $ActivityLinkVoteA = ActivityLinkVoteA::model()->findAllByAttributes(array('vote_q_id'=>$id));
//            $htmla='';
//            foreach ($ActivityLinkVoteA as $k=>$v){
//                  $htmla .= ''.($k+1).':<input type="text" class="m-wrap small" name="ActivityLinkVoteA['.($k+1).']['.$v['sort'].']" value="'.$v['a_content'].'" /> ';
//
//            }
//            echo $htmla;  
//            
            
            echo '<div class="control-group"><label class="control-label">Default</label><div class="controls"><input id="tags_1" type="text" class="m-wra tags" value="foo,bar,baz,roffle" /></div></div>';
            
        }
        
         public function get_question($model){
            
           
        // echo CHtml::activeTextField($model,'q_content');
          
                  $htmla = '<input type="text"  name="ActivityLinkVoteQ[q_content]['.$model->id.']" value="'.$model->q_content.'">';

           
            echo $htmla;  
            
        }
}